home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / cea.bst < prev    next >
Text File  |  1992-09-14  |  26KB  |  1,124 lines

  1. %% Save file as: CEA.BST                        Source: FILESERV@SHSU.BITNET
  2. % Name: cea.bst
  3. % Description: BibTeX style for Computers and Electronics in Agriculture
  4. % Keywords: BibTeX, bibliography style
  5. % Author: James Darrell McCauley <jdm5548@diamond.tamu.edu>
  6. % Latest Version: Version 0.1 <13 Mar 1992>
  7. % Archives: niord.shsu.edu or FILESERV@SHSU.BITNET
  8. % Note: This is a hack of apalike.bst and not official by Elsevier Sci Pub
  9. %       (See CHANGE LOG below)
  10. % See also: cea.sty
  11. %
  12. % CHANGE LOG
  13. % Date          Ver  Changes
  14. % <13 Mar 1992> 0.9  Modified from apalike.bst <jdm5548@diamond.tamu.edu>
  15. %                    BibTeX `apalike' bibliography style (24-Jan-88 version)
  16. %
  17. % BibTeX `cea' bibliography style <13 Mar 1992>
  18. % Adapted from the `apalike' bibliography style (24-Jan-88 version)
  19. % Adapted from the `alpha' style, version 0.99a; for BibTeX version 0.99a.
  20. % Copyright (C) 1988, all rights reserved.
  21. % Copying of this file is allowed, provided that if you make any changes at all
  22. % you name it something other than `apalike.bst'.
  23. % This restriction helps ensure that all copies are identical.
  24. % Differences between this style and `alpha' are generally heralded by a `%'.
  25. % The file btxbst.doc has the documentation for alpha.bst.
  26. %
  27. % This style should be used with the `cea' LaTeX style (cea.sty).
  28. % \cite's come out like "(Jones, 1986)" in the text but there are no labels
  29. % in the bibliography, and something like "1986" comes out immediately
  30. % after the author.  Author (and editor) names appear as last name, comma,
  31. % initials.  A `year' field is required for every entry, and so is either
  32. % an author (or in some cases, an editor) field or a key field.
  33. %
  34. % Editorial note:
  35. % Many journals, such as Computers and Electronics in Agriculture,
  36. % require a style like `apalike', but I strongly, strongly, strongly
  37. % recommend that you not use it if you have a choice---use something
  38. % like `plain' instead.  Mary-Claire van Leunen (A Handbook for
  39. % Scholars, Knopf, 1979) argues convincingly that a style like `plain'
  40. % encourages better writing than one like `apalike'.  Furthermore the
  41. % strongest arguments for using an author-date style like
  42. % `apalike'---that it's "the most practical" (The Chicago Manual of
  43. % Style, University of Chicago Press, thirteenth edition, 1982, pages
  44. % 400--401)---fall flat on their face with the new computer-typesetting
  45. % technology.  For instance page 401 anachronistically states "The chief
  46. % disadvantage of [a style like `plain'] is that additions or deletions
  47. % cannot be made after the manuscript is typed without changing numbers
  48. % in both text references and list."  LaTeX sidesteps the disadvantage.
  49. %
  50.  
  51. ENTRY
  52.   { address
  53.     author
  54.     booktitle
  55.     chapter
  56.     edition
  57.     editor
  58.     howpublished
  59.     institution
  60.     journal
  61.     key
  62. %    month              not used in apalike
  63.     note
  64.     number
  65.     organization
  66.     pages
  67.     publisher
  68.     school
  69.     series
  70.     title
  71.     type
  72.     volume
  73.     year
  74.   }
  75.   {}
  76.   { label extra.label sort.label }
  77.  
  78. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  79.  
  80. FUNCTION {init.state.consts}
  81. { #0 'before.all :=
  82.   #1 'mid.sentence :=
  83.   #2 'after.sentence :=
  84.   #3 'after.block :=
  85. }
  86.  
  87. STRINGS { s t }
  88.  
  89. FUNCTION {output.nonnull}
  90. { 's :=
  91.   output.state mid.sentence =
  92.     { ", " * write$ }
  93.     { output.state after.block =
  94.         { add.period$ write$
  95.           newline$
  96.           "\newblock " write$
  97.         }
  98.         { output.state before.all =
  99.             'write$
  100.             { add.period$ " " * write$ }
  101.           if$
  102.         }
  103.       if$
  104.       mid.sentence 'output.state :=
  105.     }
  106.   if$
  107.   s
  108. }
  109.  
  110. FUNCTION {output}
  111. { duplicate$ empty$
  112.     'pop$
  113.     'output.nonnull
  114.   if$
  115. }
  116.  
  117. FUNCTION {output.check}
  118. { 't :=
  119.   duplicate$ empty$
  120.     { pop$ "empty " t * " in " * cite$ * warning$ }
  121.     'output.nonnull
  122.   if$
  123. }
  124.  
  125. %                                       apalike needs this function because
  126. %                                       the year has special punctuation;
  127. %                                       apalike ignores the month
  128. FUNCTION {output.year.check}
  129. { year empty$
  130.     { "empty year in " cite$ * warning$ }
  131.     { write$
  132.       " " year * extra.label * "" *
  133.       mid.sentence 'output.state :=
  134.     }
  135.   if$
  136. }
  137.  
  138. FUNCTION {output.bibitem}
  139. { newline$
  140.   "\bibitem[" write$
  141.   label write$
  142.   "]{" write$
  143.   cite$ write$
  144.   "}" write$
  145.   newline$
  146.   ""
  147.   before.all 'output.state :=
  148. }
  149.  
  150. FUNCTION {fin.entry}
  151. { add.period$
  152.   write$
  153.   newline$
  154. }
  155.  
  156. FUNCTION {unpub.note}
  157. { add.period$
  158.   write$
  159.   " (unpubl.)"
  160.   write$
  161.   newline$
  162. }
  163.  
  164. FUNCTION {new.block}
  165. { output.state before.all =
  166.     'skip$
  167.     { after.block 'output.state := }
  168.   if$
  169. }
  170.  
  171. FUNCTION {new.sentence}
  172. { output.state after.block =
  173.     'skip$
  174.     { output.state before.all =
  175.         'skip$
  176.         { after.sentence 'output.state := }
  177.       if$
  178.     }
  179.   if$
  180. }
  181.  
  182. FUNCTION {not}
  183. {   { #0 }
  184.     { #1 }
  185.   if$
  186. }
  187.  
  188. FUNCTION {and}
  189. {   'skip$
  190.     { pop$ #0 }
  191.   if$
  192. }
  193.  
  194. FUNCTION {or}
  195. {   { pop$ #1 }
  196.     'skip$
  197.   if$
  198. }
  199.  
  200. FUNCTION {new.block.checkb}
  201. { empty$
  202.   swap$ empty$
  203.   and
  204.     'skip$
  205.     'new.block
  206.   if$
  207. }
  208.  
  209. FUNCTION {field.or.null}
  210. { duplicate$ empty$
  211.     { pop$ "" }
  212.     'skip$
  213.   if$
  214. }
  215.  
  216. FUNCTION {emphasize}
  217. { duplicate$ empty$
  218.     { pop$ "" }
  219.     { "{\rm " swap$ * "}" * }           % changed from \em to \rm
  220.   if$
  221. }
  222.  
  223. INTEGERS { nameptr namesleft numnames }
  224.  
  225. FUNCTION {format.names}
  226. { 's :=
  227.   #1 'nameptr :=
  228.   s num.names$ 'numnames :=
  229.   numnames 'namesleft :=
  230.     { namesleft #0 > }
  231.     { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't :=   % last name first
  232.       nameptr #1 >
  233.         { namesleft #1 >
  234.             { ", " * t * }
  235.             { numnames #2 >
  236.                 { "," * }
  237.                 'skip$
  238.               if$
  239.               t "others" =
  240.                 { " et~al." * }
  241.                 { " and " * t * }
  242.               if$
  243.             }
  244.           if$
  245.         }
  246.         't
  247.       if$
  248.       nameptr #1 + 'nameptr :=
  249.       namesleft #1 - 'namesleft :=
  250.     }
  251.   while$
  252. }
  253.  
  254. FUNCTION {format.authors}
  255. { author empty$
  256.     { "" }
  257.     { author format.names }
  258.   if$
  259. }
  260.  
  261. FUNCTION {format.key}                   % this function is just for apalike
  262. { empty$
  263.     { key field.or.null }
  264.     { "" }
  265.   if$
  266. }
  267.  
  268. FUNCTION {format.editors}
  269. { editor empty$
  270.     { "" }
  271.     { editor format.names
  272.       editor num.names$ #1 >
  273.         { " (Editors)" * }
  274.         { " (Editor)" * }
  275.       if$
  276.     }
  277.   if$
  278. }
  279.  
  280. FUNCTION {format.title}
  281. { title empty$
  282.     { "" }
  283.     { title "t" change.case$ }
  284.   if$
  285. }
  286.  
  287. FUNCTION {n.dashify}
  288. { 't :=
  289.   ""
  290.     { t empty$ not }
  291.     { t #1 #1 substring$ "-" =
  292.         { t #1 #2 substring$ "--" = not
  293.             { "--" *
  294.               t #2 global.max$ substring$ 't :=
  295.             }
  296.             {   { t #1 #1 substring$ "-" = }
  297.                 { "-" *
  298.                   t #2 global.max$ substring$ 't :=
  299.                 }
  300.               while$
  301.             }
  302.           if$
  303.         }
  304.         { t #1 #1 substring$ *
  305.           t #2 global.max$ substring$ 't :=
  306.         }
  307.       if$
  308.     }
  309.   while$
  310. }
  311.  
  312. FUNCTION {format.btitle}
  313. { title emphasize
  314. }
  315.  
  316. FUNCTION {tie.or.space.connect}
  317. { duplicate$ text.length$ #3 <
  318.     { "~" }
  319.     { " " }
  320.   if$
  321.   swap$ * *
  322. }
  323.  
  324. FUNCTION {either.or.check}
  325. { empty$
  326.     'pop$
  327.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  328.   if$
  329. }
  330.  
  331. FUNCTION {format.bvolume}
  332. { volume empty$
  333.     { "" }
  334.     { "volume" volume tie.or.space.connect
  335.       series empty$
  336.         'skip$
  337.         { " of " * series emphasize * }
  338.       if$
  339.       "volume and number" number either.or.check
  340.     }
  341.   if$
  342. }
  343.  
  344. FUNCTION {format.number.series}
  345. { volume empty$
  346.     { number empty$
  347.         { series field.or.null }
  348.         { output.state mid.sentence =
  349.             { "number" }
  350.             { "Number" }
  351.           if$
  352.           number tie.or.space.connect
  353.           series empty$
  354.             { "there's a number but no series in " cite$ * warning$ }
  355.             { " in " * series * }
  356.           if$
  357.         }
  358.       if$
  359.     }
  360.     { "" }
  361.   if$
  362. }
  363.  
  364. FUNCTION {format.edition}
  365. { edition empty$
  366.     { "" }
  367.     { output.state mid.sentence =
  368.         { edition "l" change.case$ " edition" * }
  369.         { edition "t" change.case$ " edition" * }
  370.       if$
  371.     }
  372.   if$
  373. }
  374.  
  375. INTEGERS { multiresult }
  376.  
  377. FUNCTION {multi.page.check}
  378. { 't :=
  379.   #0 'multiresult :=
  380.     { multiresult not
  381.       t empty$ not
  382.       and
  383.     }
  384.     { t #1 #1 substring$
  385.       duplicate$ "-" =
  386.       swap$ duplicate$ "," =
  387.       swap$ "+" =
  388.       or or
  389.         { #1 'multiresult := }
  390.         { t #2 global.max$ substring$ 't := }
  391.       if$
  392.     }
  393.   while$
  394.   multiresult
  395. }
  396.  
  397. FUNCTION {format.pages}
  398. { pages empty$
  399.     { "" }
  400.     { pages multi.page.check
  401.         { "pages" pages n.dashify tie.or.space.connect }
  402.         { "page" pages tie.or.space.connect }
  403.       if$
  404.     }
  405.   if$
  406. }
  407.  
  408. FUNCTION {format.vol.num.pages}
  409. { volume field.or.null
  410.   number empty$
  411.     'skip$
  412.     { "(" number * ")" * *
  413.       volume empty$
  414.         { "there's a number but no volume in " cite$ * warning$ }
  415.         'skip$
  416.       if$
  417.     }
  418.   if$
  419.   pages empty$
  420.     'skip$
  421.     { duplicate$ empty$
  422.         { pop$ format.pages }
  423.         { ":" * pages n.dashify * }
  424.       if$
  425.     }
  426.   if$
  427. }
  428.  
  429. FUNCTION {format.chapter.pages}
  430. { chapter empty$
  431.     'format.pages
  432.     { type empty$
  433.         { "chapter" }
  434.         { type "l" change.case$ }
  435.       if$
  436.       chapter tie.or.space.connect
  437.       pages empty$
  438.         'skip$
  439.         { ", " * format.pages * }
  440.       if$
  441.     }
  442.   if$
  443. }
  444.  
  445. FUNCTION {format.in.ed.booktitle}
  446. { booktitle empty$
  447.     { "" }
  448.     { editor empty$
  449.         { "In: " booktitle emphasize * }
  450.         { "In: " format.editors * ", " * booktitle emphasize * }
  451.       if$
  452.     }
  453.   if$
  454. }
  455.  
  456. FUNCTION {format.thesis.type}
  457. { type empty$
  458.     'skip$
  459.     { pop$
  460.       type "t" change.case$
  461.     }
  462.   if$
  463. }
  464.  
  465. FUNCTION {format.tr.number}
  466. { type empty$
  467.     { "Technical Report" }
  468.     'type
  469.   if$
  470.   number empty$
  471.     { "t" change.case$ }
  472.     { number tie.or.space.connect }
  473.   if$
  474. }
  475.  
  476. FUNCTION {format.article.crossref}
  477. { "In:"                                                 % this is for apalike
  478.   " \cite{" * crossref * "}" *
  479. }
  480.  
  481. FUNCTION {format.book.crossref}
  482. { volume empty$
  483.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  484.       "In: "
  485.     }
  486.     { "Volume" volume tie.or.space.connect
  487.       " of " *
  488.     }
  489.   if$
  490.   "\cite{" * crossref * "}" *                           % this is for apalike
  491. }
  492.  
  493. FUNCTION {format.incoll.inproc.crossref}
  494. { "In:"                                                 % this is for apalike
  495.   " \cite{" * crossref * "}" *
  496. }
  497.  
  498. FUNCTION {article}
  499. { output.bibitem
  500.   format.authors "author" output.check
  501.   author format.key output                              % special for
  502.   output.year.check                                     % apalike
  503.   new.block
  504.   format.title "title" output.check
  505.   new.block
  506.   crossref missing$
  507.     { journal emphasize "journal" output.check
  508.       format.vol.num.pages output
  509.     }
  510.     { format.article.crossref output.nonnull
  511.       format.pages output
  512.     }
  513.   if$
  514.   new.block
  515.   note output
  516.   fin.entry
  517. }
  518.  
  519. FUNCTION {book}
  520. { output.bibitem
  521.   author empty$
  522.     { format.editors "author and editor" output.check
  523.       editor format.key output
  524.     }
  525.     { format.authors output.nonnull
  526.       crossref missing$
  527.         { "author and editor" editor either.or.check }
  528.         'skip$
  529.       if$
  530.     }
  531.   if$
  532.   output.year.check                             % special for apalike
  533.   new.block
  534.   format.btitle "title" output.check
  535.   crossref missing$
  536.     { format.bvolume output
  537.       new.block
  538.       format.number.series output
  539.       new.sentence
  540.       publisher "publisher" output.check
  541.       address output
  542.     }
  543.     { new.block
  544.       format.book.crossref output.nonnull
  545.     }
  546.   if$
  547.   format.edition output
  548.   new.block
  549.   note output
  550.   fin.entry
  551. }
  552.  
  553. FUNCTION {booklet}
  554. { output.bibitem
  555.   format.authors output
  556.   author format.key output                              % special for
  557.   output.year.check                                     % apalike
  558.   new.block
  559.   format.title "title" output.check
  560.   new.block
  561.   howpublished output
  562.   address output
  563.   new.block
  564.   note output
  565.   fin.entry
  566. }
  567.  
  568. FUNCTION {inbook}
  569. { output.bibitem
  570.   author empty$
  571.     { format.editors "author and editor" output.check
  572.       editor format.key output
  573.     }
  574.     { format.authors output.nonnull
  575.       crossref missing$
  576.         { "author and editor" editor either.or.check }
  577.         'skip$
  578.       if$
  579.     }
  580.   if$
  581.   output.year.check                             % special for apalike
  582.   new.block
  583.   format.btitle "title" output.check
  584.   crossref missing$
  585.     { format.bvolume output
  586.       format.chapter.pages "chapter and pages" output.check
  587.       new.block
  588.       format.number.series output
  589.       new.sentence
  590.       publisher "publisher" output.check
  591.       address output
  592.     }
  593.     { format.chapter.pages "chapter and pages" output.check
  594.       new.block
  595.       format.book.crossref output.nonnull
  596.     }
  597.   if$
  598.   format.edition output
  599.   new.block
  600.   note output
  601.   fin.entry
  602. }
  603.  
  604. FUNCTION {incollection}
  605. { output.bibitem
  606.   format.authors "author" output.check
  607.   author format.key output                              % special for
  608.   output.year.check                                     % apalike
  609.   new.block
  610.   format.title "title" output.check
  611.   new.block
  612.   crossref missing$
  613.     { format.in.ed.booktitle "booktitle" output.check
  614.       format.bvolume output
  615.       format.number.series output
  616.       format.chapter.pages output
  617.       new.sentence
  618.       publisher "publisher" output.check
  619.       address output
  620.       format.edition output
  621.     }
  622.     { format.incoll.inproc.crossref output.nonnull
  623.       format.chapter.pages output
  624.     }
  625.   if$
  626.   new.block
  627.   note output
  628.   fin.entry
  629. }
  630.  
  631. FUNCTION {inproceedings}
  632. { output.bibitem
  633.   format.authors "author" output.check
  634.   author format.key output                              % special for
  635.   output.year.check                                     % apalike
  636.   new.block
  637.   format.title "title" output.check
  638.   new.block
  639.   crossref missing$
  640.     { format.in.ed.booktitle "booktitle" output.check
  641.       address output                                    % for apalike
  642.       new.sentence                                      % there's no year
  643.       organization output                               % here so things
  644.       publisher output                                  % are simpler
  645. %      format.bvolume output
  646. %      format.number.series output
  647. %      format.pages output
  648.       format.vol.num.pages output
  649.     }
  650.     { format.incoll.inproc.crossref output.nonnull
  651.       format.pages output
  652.     }
  653.   if$
  654.   new.block
  655.   note output
  656.   fin.entry
  657. }
  658.  
  659. FUNCTION {conference} { inproceedings }
  660.  
  661. FUNCTION {manual}
  662. { output.bibitem
  663.   format.authors output
  664.   author format.key output                              % special for
  665.   output.year.check                                     % apalike
  666.   new.block
  667.   format.btitle "title" output.check
  668.   organization address new.block.checkb
  669.   organization output
  670.   address output
  671.   format.edition output
  672.   new.block
  673.   note output
  674.   fin.entry
  675. }
  676.  
  677. FUNCTION {mastersthesis}
  678. { output.bibitem
  679.   format.authors "author" output.check
  680.   author format.key output                              % special for
  681.   output.year.check                                     % apalike
  682.   new.block
  683.   format.title "title" output.check
  684.   new.block
  685.   "Master's thesis" format.thesis.type output.nonnull
  686.   school "school" output.check
  687.   address output
  688.   new.block
  689.   note output
  690.   fin.entry
  691. }
  692.  
  693. FUNCTION {misc}
  694. { output.bibitem
  695.   format.authors output
  696.   author format.key output                              % special for
  697.   output.year.check                                     % apalike
  698.   new.block
  699.   format.title output
  700.   new.block
  701.   howpublished output
  702.   new.block
  703.   note output
  704.   fin.entry
  705. }
  706.  
  707. FUNCTION {phdthesis}
  708. { output.bibitem
  709.   format.authors "author" output.check
  710.   author format.key output                              % special for
  711.   output.year.check                                     % apalike
  712.   new.block
  713.   format.btitle "title" output.check
  714.   new.block
  715.   "PhD thesis" format.thesis.type output.nonnull
  716.   school "school" output.check
  717.   address output
  718.   new.block
  719.   note output
  720.   fin.entry
  721. }
  722.  
  723. FUNCTION {proceedings}
  724. { output.bibitem
  725.   format.editors output
  726.   editor format.key output                              % special for
  727.   output.year.check                                     % apalike
  728.   new.block
  729.   format.btitle "title" output.check
  730.   format.bvolume output
  731.   format.number.series output
  732.   address output                                % for apalike
  733.   new.sentence                                  % we always output
  734.   organization output                           % a nonempty organization
  735.   publisher output                              % here
  736.   new.block
  737.   note output
  738.   fin.entry
  739. }
  740.  
  741. FUNCTION {techreport}
  742. { output.bibitem
  743.   format.authors "author" output.check
  744.   author format.key output                              % special for
  745.   output.year.check                                     % apalike
  746.   new.block
  747.   format.title "title" output.check
  748.   new.block
  749.   format.tr.number output.nonnull
  750.   institution "institution" output.check
  751.   address output
  752.   new.block
  753.   note output
  754.   fin.entry
  755. }
  756.  
  757. FUNCTION {unpublished}
  758. { output.bibitem
  759.   format.authors "author" output.check
  760.   author format.key output                              % special for
  761.   output.year.check                                     % apalike
  762.   new.block
  763.   format.title "title" output.check
  764.   new.block
  765.   note "note" output.check
  766.   unpub.note
  767. %  fin.entry
  768. }
  769.  
  770. FUNCTION {default.type} { misc }
  771.  
  772. MACRO {jan} {"January"}
  773.  
  774. MACRO {feb} {"February"}
  775.  
  776. MACRO {mar} {"March"}
  777.  
  778. MACRO {apr} {"April"}
  779.  
  780. MACRO {may} {"May"}
  781.  
  782. MACRO {jun} {"June"}
  783.  
  784. MACRO {jul} {"July"}
  785.  
  786. MACRO {aug} {"August"}
  787.  
  788. MACRO {sep} {"September"}
  789.  
  790. MACRO {oct} {"October"}
  791.  
  792. MACRO {nov} {"November"}
  793.  
  794. MACRO {dec} {"December"}
  795.  
  796. MACRO {acmcs} {"ACM Computing Surveys"}
  797.  
  798. MACRO {acta} {"Acta Informatica"}
  799.  
  800. MACRO {cacm} {"Communications of the ACM"}
  801.  
  802. MACRO {ibmjrd} {"IBM Journal of Research and Development"}
  803.  
  804. MACRO {ibmsj} {"IBM Systems Journal"}
  805.  
  806. MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
  807.  
  808. MACRO {ieeetc} {"IEEE Transactions on Computers"}
  809.  
  810. MACRO {ieeetcad}
  811.  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
  812.  
  813. MACRO {ipl} {"Information Processing Letters"}
  814.  
  815. MACRO {jacm} {"Journal of the ACM"}
  816.  
  817. MACRO {jcss} {"Journal of Computer and System Sciences"}
  818.  
  819. MACRO {scp} {"Science of Computer Programming"}
  820.  
  821. MACRO {sicomp} {"SIAM Journal on Computing"}
  822.  
  823. MACRO {tocs} {"ACM Transactions on Computer Systems"}
  824.  
  825. MACRO {tods} {"ACM Transactions on Database Systems"}
  826.  
  827. MACRO {tog} {"ACM Transactions on Graphics"}
  828.  
  829. MACRO {toms} {"ACM Transactions on Mathematical Software"}
  830.  
  831. MACRO {toois} {"ACM Transactions on Office Information Systems"}
  832.  
  833. MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
  834.  
  835. MACRO {tcs} {"Theoretical Computer Science"}
  836.  
  837. READ
  838.  
  839. FUNCTION {sortify}
  840. { purify$
  841.   "l" change.case$
  842. }
  843.  
  844. INTEGERS { len }
  845.  
  846. FUNCTION {chop.word}
  847. { 's :=
  848.   'len :=
  849.   s #1 len substring$ =
  850.     { s len #1 + global.max$ substring$ }
  851.     's
  852.   if$
  853. }
  854.  
  855. %                       There are three apalike cases: one person (Jones),
  856. %                       two (Jones and de~Bruijn), and more (Jones et~al.).
  857. %                       This function is much like format.crossref.editors.
  858. %
  859. FUNCTION {format.lab.names}
  860. { 's :=
  861.   s #1 "{vv~}{ll}" format.name$
  862.   s num.names$ duplicate$
  863.   #2 >
  864.     { pop$ " et~al." * }
  865.     { #2 <
  866.         'skip$
  867.         { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  868.             { " et~al." * }
  869.             { " and " * s #2 "{vv~}{ll}" format.name$ * }
  870.           if$
  871.         }
  872.       if$
  873.     }
  874.   if$
  875. }
  876.  
  877. FUNCTION {author.key.label}
  878. { author empty$
  879.     { key empty$
  880.         { cite$ #1 #3 substring$ }
  881.         'key                                    % apalike uses the whole key
  882.       if$
  883.     }
  884.     { author format.lab.names }
  885.   if$
  886. }
  887.  
  888. FUNCTION {author.editor.key.label}
  889. { author empty$
  890.     { editor empty$
  891.         { key empty$
  892.             { cite$ #1 #3 substring$ }
  893.             'key                                % apalike uses the whole key
  894.           if$
  895.         }
  896.         { editor format.lab.names }
  897.       if$
  898.     }
  899.     { author format.lab.names }
  900.   if$
  901. }
  902.  
  903. FUNCTION {editor.key.label}
  904. { editor empty$
  905.     { key empty$
  906.         { cite$ #1 #3 substring$ }
  907.         'key                    % apalike uses the whole key, no organization
  908.       if$
  909.     }
  910.     { editor format.lab.names }
  911.   if$
  912. }
  913.  
  914. FUNCTION {calc.label}
  915. { type$ "book" =
  916.   type$ "inbook" =
  917.   or
  918.     'author.editor.key.label
  919.     { type$ "proceedings" =
  920.         'editor.key.label                       % apalike ignores organization
  921.         'author.key.label                       % for labeling and sorting
  922.       if$
  923.     }
  924.   if$
  925.   ", "                                                  % these three lines are
  926.   *                                                     % for apalike, which
  927.   year field.or.null purify$ #-1 #4 substring$          % uses all four digits
  928.   *
  929.   'label :=
  930. }
  931.  
  932. FUNCTION {sort.format.names}
  933. { 's :=
  934.   #1 'nameptr :=
  935.   ""
  936.   s num.names$ 'numnames :=
  937.   numnames 'namesleft :=
  938.     { namesleft #0 > }
  939.     { nameptr #1 >
  940.         { "   " * }
  941.         'skip$
  942.       if$                                               % apalike uses initials
  943.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't := % <= here
  944.       nameptr numnames = t "others" = and
  945.         { "et al" * }
  946.         { t sortify * }
  947.       if$
  948.       nameptr #1 + 'nameptr :=
  949.       namesleft #1 - 'namesleft :=
  950.     }
  951.   while$
  952. }
  953.  
  954. FUNCTION {sort.format.title}
  955. { 't :=
  956.   "A " #2
  957.     "An " #3
  958.       "The " #4 t chop.word
  959.     chop.word
  960.   chop.word
  961.   sortify
  962.   #1 global.max$ substring$
  963. }
  964.  
  965. FUNCTION {author.sort}
  966. { author empty$
  967.     { key empty$
  968.         { "to sort, need author or key in " cite$ * warning$
  969.           ""
  970.         }
  971.         { key sortify }
  972.       if$
  973.     }
  974.     { author sort.format.names }
  975.   if$
  976. }
  977.  
  978. FUNCTION {author.editor.sort}
  979. { author empty$
  980.     { editor empty$
  981.         { key empty$
  982.             { "to sort, need author, editor, or key in " cite$ * warning$
  983.               ""
  984.             }
  985.             { key sortify }
  986.           if$
  987.         }
  988.         { editor sort.format.names }
  989.       if$
  990.     }
  991.     { author sort.format.names }
  992.   if$
  993. }
  994.  
  995. FUNCTION {editor.sort}
  996. { editor empty$
  997.     { key empty$
  998.         { "to sort, need editor or key in " cite$ * warning$
  999.           ""
  1000.         }
  1001.         { key sortify }
  1002.       if$
  1003.     }
  1004.     { editor sort.format.names }
  1005.   if$
  1006. }
  1007.  
  1008. %                       apalike uses two sorting passes; the first one sets the
  1009. %                       labels so that the `a's, `b's, etc. can be computed;
  1010. %                       the second pass puts the references in "correct" order.
  1011. %                       The presort function is for the first pass. It computes
  1012. %                       label, sort.label, and title, and then concatenates.
  1013. FUNCTION {presort}
  1014. { calc.label
  1015.   label sortify
  1016.   "    "
  1017.   *
  1018.   type$ "book" =
  1019.   type$ "inbook" =
  1020.   or
  1021.     'author.editor.sort
  1022.     { type$ "proceedings" =
  1023.         'editor.sort
  1024.         'author.sort
  1025.       if$
  1026.     }
  1027.   if$
  1028.   #1 entry.max$ substring$      % for
  1029.   'sort.label :=                % apalike
  1030.   sort.label                    % style
  1031.   *
  1032.   "    "
  1033.   *
  1034.   title field.or.null
  1035.   sort.format.title
  1036.   *
  1037.   #1 entry.max$ substring$
  1038.   'sort.key$ :=
  1039. }
  1040.  
  1041. ITERATE {presort}
  1042.  
  1043. SORT            % by label, sort.label, title---for final label calculation
  1044.  
  1045. STRINGS { last.label next.extra }       % apalike labels are only for the text;
  1046.  
  1047. INTEGERS { last.extra.num }             % there are none in the bibliography
  1048.  
  1049. FUNCTION {initialize.extra.label.stuff} % and hence there is no `longest.label'
  1050. { #0 int.to.chr$ 'last.label :=
  1051.   "" 'next.extra :=
  1052.   #0 'last.extra.num :=
  1053. }
  1054.  
  1055. FUNCTION {forward.pass}
  1056. { last.label label =
  1057.     { last.extra.num #1 + 'last.extra.num :=
  1058.       last.extra.num int.to.chr$ 'extra.label :=
  1059.     }
  1060.     { "a" chr.to.int$ 'last.extra.num :=
  1061.       "" 'extra.label :=
  1062.       label 'last.label :=
  1063.     }
  1064.   if$
  1065. }
  1066.  
  1067. FUNCTION {reverse.pass}
  1068. { next.extra "b" =
  1069.     { "a" 'extra.label := }
  1070.     'skip$
  1071.   if$
  1072.   label extra.label * 'label :=
  1073.   extra.label 'next.extra :=
  1074. }
  1075.  
  1076. EXECUTE {initialize.extra.label.stuff}
  1077.  
  1078. ITERATE {forward.pass}
  1079.  
  1080. REVERSE {reverse.pass}
  1081.  
  1082. %                               Now that the label is right we sort for real,
  1083. %                               on sort.label then year then title.  This is
  1084. %                               for the second sorting pass.
  1085. FUNCTION {bib.sort.order}
  1086. { sort.label
  1087.   "    "
  1088.   *
  1089.   year field.or.null sortify
  1090.   *
  1091.   "    "
  1092.   *
  1093.   title field.or.null
  1094.   sort.format.title
  1095.   *
  1096.   #1 entry.max$ substring$
  1097.   'sort.key$ :=
  1098. }
  1099.  
  1100. ITERATE {bib.sort.order}
  1101.  
  1102. SORT            % by sort.label, year, title---giving final bibliography order
  1103.  
  1104. FUNCTION {begin.bib}
  1105. { preamble$ empty$                              % no \etalchar in apalike
  1106.     'skip$
  1107.     { preamble$ write$ newline$ }
  1108.   if$
  1109.   "\begin{thebibliography}{}" write$ newline$           % no labels in apalike
  1110. }
  1111.  
  1112. EXECUTE {begin.bib}
  1113.  
  1114. EXECUTE {init.state.consts}
  1115.  
  1116. ITERATE {call.type$}
  1117.  
  1118. FUNCTION {end.bib}
  1119. { newline$
  1120.   "\end{thebibliography}" write$ newline$
  1121. }
  1122.  
  1123. EXECUTE {end.bib}
  1124.